Is it always possible to arrange the numbers from 1 to 2n in a circle so that each adjacent pair sums to a prime? As of 2016, solutions have been found for every case up to n = 106 — but no one has yet proven that it’s always possible. From Futility Closet.
I was intrigued by this mostly as a programming learning opportunity. A data structure for the circle of numbers could be a linked list. I have never implemented one of these in JavaScript and thought it would be a fun challenge. Additionally, the logical flow of the search for prime sums posed a second challenge. As you find prime sums you may get to a point where you can no longer find one and need to drop back and replace an earlier prime sum. So backtracking and keeping tabs on prime sums that have been eliminated poses the second challenge.
I am going to try something a little different here and write pseudocode to map out how I expect the program logic to flow.
The linked list code used here is from Learners Bucket.
The limit is based solely on your patience. A limit of 100,000,000 takes about 20 seconds to calculate. Of course, the largest possible factorion is less than 99,999,999 as 8 X 9! = 2,903,040. Further digits do not grow fast enough as 9! < 1,000,000.
Reload the browser window/tab between calculations if you don't want successive calculations appended.